package com.school.util;

import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MapperToJson {

	public static String toJson(Object ob){
		ObjectMapper om=new ObjectMapper();
		String strJson="";
	try {
		 strJson=	om.writeValueAsString(ob);
	} catch (JsonProcessingException e) {
		e.printStackTrace();
	}
		return strJson;
		
	}
	public static String toJson(List<?> list){
		ObjectMapper om=new ObjectMapper();
		String strJson="";
	try {
		 strJson=	om.writeValueAsString(list);
	} catch (JsonProcessingException e) {
		e.printStackTrace();
	}
		return strJson;
		
	}
	
	/**
	 * 设备开关机标识转换
	 * @param data
	 * @return
	 */
	public static String intToBoolean(String data){
		 if(data.equals("0")){
			 return "false";
		 }else{
			 
			 return "true";
		 }
	}
	public static String booleanToInt(String data){
		if(data.equals("false")){
			return "0";
		}else{
			return "1";
		}
		
	}
	
}
